package com.example.gybicycle.controller.web;
import  com.alibaba.fastjson.JSON;

import com.example.gybicycle.entity.BikeFailure;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.example.gybicycle.common.Log.SysLoging;
import com.example.gybicycle.common.entity.NormalPage;
import com.example.gybicycle.common.entity.Result;
import com.example.gybicycle.common.util.*;
import com.example.gybicycle.entity.SysCaption;
import com.example.gybicycle.entity.LoginInfo;
import com.example.gybicycle.entity.SysUser;
import com.example.gybicycle.service.SysCaptionService;



@Tag(name = "说明")
@RestController
@RequestMapping("/web/caption")
public class SysCaptionController {
    @Autowired
    private SysCaptionService captionService;
    @PostMapping("/get")
    @SysLoging("说明管理-查看")
    @Operation(summary = "根据id查看")
    @RequiresPermissions("caption:get")
    @ApiOperationSupport(includeParameters = {"caption.id"})
    public Result get(@RequestBody SysCaption caption){
      caption=captionService.get(caption.getId());
        return Result.success(caption);
    }
    @PostMapping("/cyclingrule")
    @Operation(summary = "骑行须知")
    @RequiresPermissions("caption:cycling")
    @ApiOperationSupport(includeParameters = {"caption.id"})
    public Result CyclingRule( ){
        SysCaption caption=captionService.get(1);
        return Result.success(caption);
    }
    @PostMapping("/pricerule")
    @Operation(summary = "计价规则")
    @RequiresPermissions("caption:price")
    @ApiOperationSupport(includeParameters = {"caption.id"})
    public Result pricerule(){
        SysCaption caption=captionService.get(2);
        return Result.success(caption);
    }
    @PostMapping("/serve")
    @Operation(summary = "一键服务")
    @RequiresPermissions("caption:serve")
    public Result serve(){
        SysCaption caption=captionService.get(3);
        return Result.success(caption);
    }
  /*  @PostMapping("/list")
    @Operation(summary =  "列表查看")
    @RequiresPermissions("caption:list")
    @SysLoging("说明管理-查看")
    public Result findList(@RequestBody(required=false)  SysCaption page){

        Page<SysCaption> list = PageHelper.startPage(page.getPage(), page.getSize()).doSelectPage(
                () ->captionService.findList(page));
        return Result.success(NormalPage.createPage(list));
    }*/
     @PostMapping("/update")
    @Operation(summary =  "保存")
    @RequiresPermissions("caption:update")
    @SysLoging("说明管理-保存")
    public Result save(@RequestBody SysCaption caption, HttpServletRequest request){
         LoginInfo loginInfo=LoginUtil.getLoginInfo(request);
        if(loginInfo==null)
            return Result.loginOut();
        if(caption.getId()==null)
            return Result.fail("未获取到ID");
        int num= captionService.update(caption);
        if(num>0)
            return Result.success(caption);
        else return Result.fail("修改失败");
    }

}